/* pfs33MapChunk.cpp
 *
 * --
 * Copyright (c) 2012, Christophe Huriaux
 * Distributed under the terms of the MIT license.
 * http://www.opensource.org/licenses/mit-license.php
 * --
 */

#include <packet/pfs33MapChunk.h>
#include <wrapper/JavaStreamWrapper.h>

pfs33MapChunk::pfs33MapChunk()
    : McPacketFromServer(0x33), x(0), y(0), z(0), sizex(0), sizey(0), sizez(0), size(0), data()
{
}

unsigned int pfs33MapChunk::length()
{
    return 1 + 4 + 2 + 4 + 1 + 1 + 1 + 4 + 0;
}

int16_t pfs33MapChunk::setField(uint8_t field, void* value)
{

    switch (field)
    {
        case 0:
        default: return 4;
        case 1: x = JavaStreamWrapper::readInt(value); return 2;
        case 2: y = JavaStreamWrapper::readShort(value); return 4;
        case 3: z = JavaStreamWrapper::readInt(value); return 1;
        case 4: sizex = JavaStreamWrapper::readByte(value); return 1;
        case 5: sizey = JavaStreamWrapper::readByte(value); return 1;
        case 6: sizez = JavaStreamWrapper::readByte(value); return 4;
        case 7: size = JavaStreamWrapper::readInt(value); return size;
        case 8: data.reserve(size); JavaArrayWrapper<uint8_t>::readArray(value, data, size); return -1;
    }
}

int32_t pfs33MapChunk::getX()
{
    return x;
}

int16_t pfs33MapChunk::getY()
{
    return y;
}

int32_t pfs33MapChunk::getZ()
{
    return z;
}

int8_t pfs33MapChunk::getSizex()
{
    return sizex;
}

int8_t pfs33MapChunk::getSizey()
{
    return sizey;
}

int8_t pfs33MapChunk::getSizez()
{
    return sizez;
}

int32_t pfs33MapChunk::getSize()
{
    return size;
}

std::vector<uint8_t>&  pfs33MapChunk::getData()
{
    return data;
}


